home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple II Magazines (PO)
/
Nibble Volume 10, No. 02 (1989-02)(MicroSPARC)(Side A).zip
/
Nibble Volume 10, No. 02 (1989-02)(MicroSPARC)(Side A).po
/
TYPE.S
< prev
next >
Wrap
Text File
|
1996-12-24
|
16KB
|
480 lines
*****************************
* TYPE Source Code *
* by Bill Tudor *
* COPYRIGHT (C) 1989 *
* BY MICROSPARC, INC. *
* CONCORD, MA 01742 *
*****************************
* Merlin 8/16
* Program/Monitor Equates:
PTR = $06 ;pointer ($06,$07)
PADDR = $08 ;temp storage
OFFSET = $09 ;index variable
COUNT = $19 ;counter
SIZE = $FA ;display size
*
HIMEM = $73 ;system; HIMEM
INBUF = $200 ;system; keyboard input buffer
KEYBD = $C000 ;system; the keyboard
STROBE = $C010 ;system; reset keyboard strobe
SPKR = $C030 ;system; speaker click
RD80COL = $C01F ;system; 80 col switch
OPLEN = $2F ;monitor; opcode length
A1L = $3C ;monitor; MOVE start
A2L = $3E ;monitor; MOVE end
A4L = $42 ;monitor; MOVE destination
CHKOPLEN = $F88E ;monitor; check opcode length
PRTAX = $F941 ;monitor; print A and X as hex
CLREOP = $FC42 ;monitor; clear from cursor down
WAIT = $FCA8 ;monitor; wait routine
CROUT = $FD8E ;monitor; CR out
PRTBYTE = $FDDA ;monitor; print A as hex
COUT = $FDED ;monitor; character out routine
MOVE = $FE2C ;monitor; MOVE
* BASIC.SYSTEM/ProDOS Equates:
EXTRNCMD = $BE06 ;BI; external command hook
ERROUT = $BE09 ;BI; handle an error
XTRNADDR = $BE50 ;BI; external command address
XLEN = $BE52 ;BI; external cmd length-1
XCNUM = $BE53 ;BI; basic command no. (0-ext)
PBITS = $BE54 ;BI; parameter bits allowed
FBITS = $BE56 ;BI; found parameter bits
VPATH1 = $BE6C ;BI; pathname buffer
GOSYSTEM = $BE70 ;BI; execute MLI call
GETBUFR = $BEF5 ;BI; allocate buffer
SSGINFO = $BEB4 ;BI; Get/Set info parm count
FIFILID = $BEB8 ;BI; file type
OSYSBUF = $BECE ;BI; I/O buffer
OREFNUM = $BED0 ;BI; Open ref. number
RWREFNUM = $BED6 ;BI; Read/Write ref. number
RWDATA = $BED7 ;BI; Read/Write data pointer
RWCOUNT = $BED9 ;BI; Read/Write byte count
CFREFNUM = $BEDE ;BI; Close ref. number
MACHID = $BF98 ;ProDOS; Machine ID byte
* Applesoft Equates:
LINUM = $1B ;basic; line number ($1B,$1C)
LINNUM = $50 ;basic; 2-byte signed integer
TOKTABL = $D0D0 ;basic; token table
LINPRT = $ED24 ;basic; print A,X as dec
ORG $2000 ;by convention
*===============================
* Program Installation:
*===============================
INSTALL LDA #>PEND-PSTART+$100
JSR GETBUFR ;buy space from BI
BCC GOTBUF
HANDLERR JMP ERROUT ;handle the error
GOTBUF STA PADDR ;save location
*===============================
* Modify the code:
*===============================
MODIFY STA MANUAL+1 ;1 to change manually
LDA #<MODSTART
STA PTR ;set program pointer
LDA #>MODSTART
STA PTR+1
MODLOOP LDY #0 ;instruction byte offset
LDA (PTR),Y ;get opcode
JSR CHKOPLEN ;check opcode length
LDY OPLEN ;put length in Y
CPY #$02 ;2=3 byte instruction
BNE NOMOD ;no modification of this one
LDA (PTR),Y ;get HOB to fix
CMP #>MODSTART ;is it below our program
BLT NOMOD ;yes/no modification
CMP #>MODEND+$200 ;is it above our program
BGE NOMOD ;yes/no modification
FIXIT SEC
SBC #>PSTART ;subtract min. location
CLC
ADC PADDR
STA (PTR),Y ;save the byte
NOMOD TYA ;put #bytes-1 into A
SEC ;to add 1 more
ADC PTR ;add #bytes-1+1 to PTR LO@@bIEsZv"$?SKYSTA NXTCMD+1 ;copy cuurent external command
LDA EXTRNCMD+2 ;to the next command in link
STA NXTCMD+2
LDA #0
STA EXTRNCMD+1 ;put our code address in BI's
LDA PADDR ;global page
STA EXTRNCMD+2
*===============================
* Move the code:
*===============================
LDA #PSTART ;start of final code
STA A1L
LDA #>PSTART
STA A1L+1 ;start adr. set
LDA #PEND ;end of final code
STA A2L
LDA #>PEND
STA A2L+1 ;end adr. set
LDA #0 ;LOB of destination
STA A4L
LDA PADDR ;HOB of destination
STA A4L+1 ;destination set
LDY #0 ;Y must contain zero
JSR MOVE ;execute monitor move routine
CLC
RTS ;return to BASIC
;installation complete
DS \ ;move to next page
*===============================
* TYPE Command Handler:
*===============================
MODSTART = * ;start of modified code
PSTART CLD ;program start
LDA VPATH1
STA PTR ;copy command pointer
LDA VPATH1+1
STA PTR+1
LDY #0
CHKCMD INY
LDA (PTR),Y ;get command character
CMP CMDTXT,Y ;compare to ours
BNE NOTOURS
CPY CMDTXT ;done checking?
BLT CHKCMD
*===============================
* Command is ours/send to be parsed:
*===============================
DEY
STY XLEN ;save command length-1
LDA #0
STA XCNUM ;mark as external command
LDA #%00000001 ;LOB of parameter bits..
STA PBITS ;filename expected
LDA #%00000100 ;HOB of parameter bits..
STA PBITS+1 ;slot/drive optional
LDA #<TYPE
STA XTRNADDR ;tell where to return
MANUAL LDA #$00 ;modify the HOB here
STA XTRNADDR+1
CLC ;mark no errors
RTS ;allow BASIC.SYSTEM to parse
*
NOTOURS SEC ;flag not our command
NXTCMD JMP $0000 ;link to next command
*===============================
* The 'real' TYPE command:
*===============================
TYPE LDA #$0A ;parm_count for GFI call
STA SSGINFO ;save parm_count
LDA #$C4 ;GET_FILE_INFO command
JSR GOSYSTEM ;fill GFI parameter list
BCC NOERROR ;open file
ER1 JMP ERROUT ;let BI handle errors
NOERROR LDA HIMEM+1 ;address of all-purpose buffer
STA OSYSBUF+1
LDY #0
STY OSYSBUF ;set open I/O buffer address
STY RWDATA ;LOB of data buffer
STY RWCOUNT+1 ;HOB of read byte count
STY LINUM
STY LINUM+1 ;zero the line count
INY
STY RWCOUNT ;only 1 byte read at a time
INY
STY RWDATA+1 ;data buffer at $200
LDA #$C8 ;OPEN command
JSR GOSYSTEM ;open the file
BCS ER1 ;handle error
LDA OREFNUM
STA RWREFNUM ;copy reference number to close
STA CFREFNUM ;and read parameter lists
*===============================
* Check file type and branch:
*===============================
JSR CROUT ;new line
JSR CLREOP ;clear the screen
LDA FIFILID ;get the file type
CMP #$04 ;Txt?
BNE :1
JMP TEXT ;handle text file
:1 CMP #$1A ;Awp?
BNE :2
JMP AWORKS ;handle AppleWorks WP file
:2 CMP #$FC ;Bas?
BNE BINFILE ;default to Bin type
JMP BASIC ;handle BASIC program
*===============================
* Handle BIN (or general file):
*===============================
BINFILE LDA MACHID ;check for II+
BMI CHK80CRD
DO40 LDA #8 ;use 8-byte (40-cols)
BNE SETSZ ;always
CHK80CRD LSR
LSR ;check bit 1
BCC DO40 ;no 80 col card to check
BIT RD80COL ;check 80-col switch
BPL DO40 ;in 40-cols
LDA #16 ;use 16-byte (80-cols)
SETSZ STA SIZE ;save display size
BIN JSR GETBYTE ;check next byte
BCC GOTBYTE ;got one
TOEXIT JMP EXIT ;done with file
GOTBYTE PHA ;save byte
JSR CROUT ;new line
LDA #"$"
JSR COUT ;print dollar sign
LDX LINUM
LDA LINUM+1 ;get current line value
JSR PRTAX ;print the 2 bytes
LDA #"-"
JSR COUT ;print spacer
PLA ;restore character
LDX SIZE ;do "size" bytes
BNE DOBYTE ;always taken
BINL1 JSR GETBYTE ;get a byte
BCC DOBYTE ;do the byte
LDA #" " ;add a space char
STA INBUF,X ;since were at EOF
LDY #3
BNE SPCS ;do 3 spaces
DOBYTE STA INBUF,X ;temp storage
JSR PRTBYTE ;print the byte
LDY #1
SPCS JSR PYSPACE ;print Y spaces
DEX
BNE BINL1 ;do a line of bytes
*-------------------------------
SCHAR LDA #"|" ;note:this is modified on
JSR COUT ;the II+ to print a space
LDX SIZE ;start at "size"
CHRLP LDA INBUF,X ;get character
ORA #$80 ;set bit 7
CMP #$A0 ;is it >= spc
BGE COK ;yes; print it
LDA #"." ;no; substitute a period
COK JSR COUT ;print the character
DEX
BNE CHRLP ;do all characters
*-------------------------------
JSR ANYKEY ;user pause/exit?
BEQ TOEXIT ;exit on esc/cntrl-c
LDA SIZE ;add "size" bytes to line
CLC
ADC LINUM
STA LINUM
BCC BIN ;do next line
INC LINUM+1 ;fix the HOB
JMP BIN ;do next line
*===============================
* Type TXT file:
*===============================
TEXT JSR GETBYTE ;get a byte
BCS EXIT3 ;exit the program
ORA #$80 ;set bit 7
CMP #$A0 ;only type printable chars
BGE PRTIT
CMP #$8D ;only allow CR/LF/FF
BEQ PRTIT
CMP #$8A ;linefeed?
BEQ DOCR
CMP #$8C ;form feed?
BNE TEXT ;ignore control codes
DOCR LDA #$8D ;convert LF/FF to CR
PRTIT JSR COUT ;print it
JSR ANYKEY ;check keyboard
BNE TEXT ;always (unless esc press)
EXIT3 JMP EXIT ;exit if esc/cntrl-c press
*===============================
* AppleWorks Word Proc. File (Awp):
*===============================
AWORKS LDX #$FF
MORE JSR GETBYTE ;read in 255+45=300 bytes
DEX
BNE MORE
LDX #45 ;skip the 300 byte header
MORE2 JSR GETBYTE
DEX
BNE MORE2
*===============================
* Loop out AWP lines:
*===============================
LINE JSR CROUT ;next line
JSR ANYKEY ;check for spc/esc/cntrl-c
BEQ EXIT3 ;exit if esc/cntrl-c
JSR GETBYTE ;get # bytes per line
BCS EXIT3 ;exit/end of file
JSR GETBYTE ;line +001 byte (ID byte)
BNE LINE ;ignore control lines
DOTXT JSR GETBYTE ;get column of first character
TAY
INY ;add 1 to it
SPCLP JSR PYSPACE ;indent over Y spaces
JSR GETBYTE ;get the # characters
AND #%01111111 ;isolate line length
TAX
CLOOP JSR GETBYTE ;get line character
ORA #$80 ;set bit 7
CMP #$A0 ;cntrl code?
BLT SKPCTRL ;skip control codes
JSR COUT ;print characters
SKPCTRL DEX
BNE CLOOP ;loop out characters
BEQ LINE ;always taken
*===============================
* Basic Program File (Bas):
*===============================
BASIC JSR CROUT ;next line
JSR ANYKEY ;check keypress
BEQ EXIT ;exit if esc/cntrl-c
JSR GETBYTE
BCS EXIT ;just in case an empty file
JSR GETBYTE ;2 bytes are garbage
JSR GETBYTE
BCS EXIT
TAX ;2 bytes are line number
JSR GETBYTE
BCS EXIT
JSR LINPRT ;print BASIC line number..
JSR PSPACE ;and a space
BASLP JSR GETBYTE ;get a character
BEQ BASIC ;end of line
BMI TOKEN ;basic token encountered
BASPRT ORA #$80
JSR COUT ;print the character
JMP BASLP ;do next one on line
TOKEN AND #%01111111 ;clear bit 7
TAX ;get commands to skip
LDA #<TOKTABL
STA PTR
LDA #>TOKTABL
STA PTR+1
JSR PSPACE ;space before token
LDY #0
CPX #0
BEQ GTLP
TKLP1 LDA (PTR),Y ;get token character
BPL INCPTR ;end of token
DEX
BEQ GOTTKN
INCPTR INC PTR ;move pointer over 1
BNE TKLP1
INC PTR+1 ;fix HOB
JMP TKLP1
GOTTKN INY
GTLP LDA (PTR),Y ;get the token
BMI LASTONE ;print last character
ORA #$80
JSR COUT ;print token characters
INY
BNE GTLP ;always taken
LASTONE JSR COUT
LDA #" "
BNE BASPRT ;always taken
*===============================
* Exit the program:
*===============================
EXIT LDA #$CC ;close command
JSR GOSYSTEM ;close the file
JSR CROUT
CLC
RTS
*-------------------------------
DOERROR PHA ;save error code
JSR EXIT ;close the file
PLA ;restore error code
SEC ;flag error
JMP ERROUT ;exit through BI
*===============================
* Subroutine GETBYTE; get file byte:
*===============================
GETBYTE LDA #$CA ;READ command
JSR GOSYSTEM ;execute command
BCS CHKEOF ;could be EOF
LDA INBUF ;get char into A..
CLC ;flag no error..
RTS ;and return
*-------------------------------
CHKEOF CMP #5
BEQ EOF
STA OFFSET ;temp storage
PLA
PLA ;"pop" off subroutine
LDA OFFSET ;restore code
JMP DOERROR ;and handle 'real' error
EOF SEC ;flag end of file
RTS ;end exit
*===============================
* Subroutine PSPACE/PYSPACE:
*===============================
PSPACE LDY #1 ;do 1 space
PYSPACE LDA #" "
:1 JSR COUT ;print Y spaces
DEY
BNE :1
RTS
*===============================
* Subroutine ANYKEY:
*===============================
ANYKEY LDA KEYBD ;check keyboard
BPL KEYOUT ;no keypress
STA STROBE ;clear keyboard
CMP #$A0 ;space?
BEQ KEY2
CHKIT CMP #$9B ;esc?
BEQ KEYOUT
CMP #$83 ;cntrl-C
KEYOUT RTS
*
KEY2 LDA KEYBD ;wait for any keypress
BPL KEY2
STA STROBE
BNE CHKIT ;always
MODEND = * ;end of modification
;do not modify text!
*===============================
* Command text:
*===============================
CMDTXT STR 'TYPE' ;our command (with length byte)
*-------------------------------
PEND = * ;end of program
LST OFF